using System;
using System.Collections.Generic;
using System.Text;

namespace KukaDataComCommon
{
    [Serializable]
    public class Location
    {

        #region Eigenschaften

        private float x;
        public float X
        {
            get { return x; }
            set { x = value; }
        }

        private float y;
        public float Y
        {
            get { return y; }
            set { y = value; }
        }

        private float z;
        public float Z
        {
            get { return z; }
            set { z = value; }
        }

        public float Length
        {
            get { return Convert.ToSingle(Math.Sqrt(Math.Pow(X, 2) + Math.Pow(Y, 2) + Math.Pow(Z, 2))); }
        }

        #endregion

        #region Konstruktor

        public Location()
            :this(445, 0, 615)
        { }

        public Location(Location copy)
            :this(copy.X, copy.Y, copy.Z)
        { }

        public Location(float x, float y, float z)
        {
            this.x = x;
            this.y = y;
            this.z = z;
        }

        public Location Copy()
        {
            return new Location(this);
        }

        #endregion

        #region Mathmatics

        public Location Subtract(Location value)
        {
            Location result = new Location();

            result.X = this.X - value.X;
            result.Y = this.Y - value.Y;
            result.Z = this.Z - value.Z;

            return result;
        }

        public Location Add(Location value)
        {
            Location result = new Location();

            result.X = this.X + value.X;
            result.Y = this.Y + value.Y;
            result.Z = this.Z + value.Z;

            return result;
        }

        public Location Multiply(float value)
        {
            Location result = new Location();

            result.X = this.X * value;
            result.Y = this.Y * value;
            result.Z = this.Z * value;

            return result;
        }

        public Location Divide(float value)
        {
            Location result = new Location();

            result.X = this.X / value;
            result.Y = this.Y / value;
            result.Z = this.Z / value;

            return result;
        }

        public Location CrossMultiply(Location value)
        {
            Location result = new Location();

            result.X = this.Y*value.Z - this.Z*value.Y;
            result.Y = this.Z*value.X - this.X*value.Z;
            result.Z = this.X*value.Y - this.Y*value.X;

            return result;
        }

        public static Location operator +(Location a, Location b)
        {
            return a.Add(b);
        }

        public static Location operator -(Location minuend, Location subtrahend)
        {
            return minuend.Subtract(subtrahend);
        }

        public static Location operator *(Location a, float b)
        {
            return a.Multiply(b);
        }

        public static Location operator *(Location a, Location b)
        {
            return a.CrossMultiply(b);
        }

        public static Location operator /(Location dividend, float divisor)
        {
            return dividend.Divide(divisor);
        }

        #endregion

        #region overrides

        public override string ToString()
        {
            return "X: " + X + " Y: " + Y + " Z: " + Z;
        }

        #endregion

    }
}
